
//带入路由模块
const Router = require('koa-router')

//中间件
const {auth} = require('../middleware/auth.middleware')
const {validator} = require('../middleware/addr.middleware')


//引入控制器
const {create,findAll,update,remove,setDefault} = require('../controller/addr.controller')


//创建路由对象
const router = new Router({
    prefix:'/address'

})

//编写路由规则

//3.1添加收货地址接口：登录，格式校验，添加收货地址
router.post('/',auth, validator({
    consignee: "string", //收货人
    phone: { type: 'string', format: /^1[3-9]\d{9}$/},
    address: "string",
}), create)

//获取地址列表
router.get('/',auth,findAll)

//修改地址
router.put("/:id",auth,validator({
    consignee: "string", //收货人
    phone: { type: 'string', format: /^1[3-9]\d{9}$/},
    address: "string",
}),update)

//删除地址
router.delete('/:id',auth,remove)

//设置默认地址
router.patch('/:id',auth,setDefault)


module.exports = router